package com.example.demo.controller;

import com.example.demo.bean.ERecord;
import com.example.demo.bean.RegionStates;
import com.example.demo.bean.UserInfo;
import com.example.demo.service.ERecordService;
import com.example.demo.service.UserInfoService;
import com.example.demo.util.TransferUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ERecordController {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private ERecordService eRecordService;

    @PostMapping("/report")
    public String report(UserInfo userInfo, ERecord eRecord){
        userInfoService.updateUserInfo(userInfo);
        System.out.println(eRecord);
        List<ERecord> eRecords = eRecordService.getERcordByUfid(userInfo.getId());
        if(eRecords.get(0).getArrival() == null){
            eRecordService.updateERecord(eRecord);
        }else{
            eRecordService.insertERecord(eRecord);
        }
        return "redirect:/userinfo";
    }
}
